﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SN.Data;
using System.Data;
using System.Text;
using Agro.Models;
using System.Reflection;
using System.Diagnostics;
using Agro.Services;
using Agro.Library;
using System.Drawing;
using Ninject;
using Newtonsoft.Json;
using SN.Core;


namespace Agro.Web.Areas.SystemManage.Controllers
{
    public class ExecSqlController : BaseController
    {
        //
        // GET: /SystemManage/ExecSql/
        [Inject]
        public IExecSqlService ExecSqlService { get; set; }

        public ActionResult ShowPage()
        {
            return View();
        }

        [HttpPost]
        public ActionResult GetResult(QueryBase query, string KeyCode)
        {

            if (KeyCode.Length < 0)
                return Json("");

            DataTable dt = ExecSqlService.ExecSql(KeyCode);
            return JqGrid(dt, query);
            //string colModel = "[";
            //int i = 0;
            //foreach (DataColumn dc in dt.Columns)
            //{
            //    if (i <= 0)
            //        colModel += string.Format("{{label: '{0}', name: '{1}', width: 100}}", dc.ColumnName, dc.ColumnName);
            //    else
            //        colModel += string.Format(",\n{{label: '{0}', name: '{1}', width: 100}}", dc.ColumnName, dc.ColumnName);
            //    i++;
            //}
            //colModel += "]";
            //object[] o =new object[2];
            //o[0] = colModel;
            //o[1] = JqGrid(dt, query);
            //return Json(o);

        }

    }
}
